<?php

namespace App\Observers\Plane;

use App\Models\Plane\Flight\FlightCabin;
use Illuminate\Support\Facades\Cache;

class FlightCabinObserver
{
    public function created(FlightCabin $flight_cabin)
    {
        $cache_key_code = "FlightCabin:{$flight_cabin->getCarrierCode()}:{$flight_cabin->getCabin()}";
        Cache::put($cache_key_code, $flight_cabin, 30 * config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param FlightCabin $flight_cabin
     * @return void
     */
    public function updated(FlightCabin $flight_cabin)
    {
        $cache_key_code = "FlightCabin:{$flight_cabin->getCarrierCode()}:{$flight_cabin->getCabin()}";
        Cache::put($cache_key_code, $flight_cabin, 30 * config('trip.ttl.day'));
    }

    public function saved(FlightCabin $flight_cabin)
    {
        $cache_key_code = "FlightCabin:{$flight_cabin->getCarrierCode()}:{$flight_cabin->getCabin()}";
        Cache::put($cache_key_code, $flight_cabin, 30 * config('trip.ttl.day'));
    }

    public function deleted(FlightCabin $flight_cabin)
    {
        $cache_key_code = "FlightCabin:{$flight_cabin->getCarrierCode()}:{$flight_cabin->getCabin()}";
        Cache::forget($cache_key_code);
    }
}
